package f_graph_basics;

import f_graph_basics.a_graph_representation.DenseGraph;
import f_graph_basics.a_graph_representation.Graph;
import f_graph_basics.a_graph_representation.SparseGraph;
import f_graph_basics.b_read_graph_from_file.ReadGraph;
import f_graph_basics.c_graph_component.GraphScan;
import f_graph_basics.d_find_path.GraphPath;
import f_graph_basics.e_shortest_path.GraphShortestPath;

import static f_graph_basics.b_read_graph_from_file.ReadGraph.readGraph;

public class MainTest {
    public static void main(String[] args) throws Exception {

        // GraphHelper.testSparseGraph1();
        // GraphHelper.testDenseGraph2();

        ///////////////////////////////
        //      0   1 - 2
        //        \     |
        //      3   4   5
        //      |     \
        //      6 - 7   8
        ////////////////////////////////
        String rootPath = ReadGraph.class.getResource("").getPath().substring(1);
        Graph g = new SparseGraph(9, false);
        g = readGraph(g, rootPath + "testG3.txt");
        assert g != null;
        GraphScan gScan = new GraphScan(g);
        System.out.println("c count : " + gScan.ccount);
        assert gScan.isConnected(0, 8);
        assert gScan.isConnected(3, 7);
        assert !gScan.isConnected(3, 1);
        assert !gScan.isConnected(4, 7);

        /////////////////////////////// find path
        //      0   1 - 2
        //      |  \     |
        //      3   4   5
        //      |     \
        //      6 - 7 - 8
        ////////////////////////////////
        Graph g1 = new DenseGraph(9, false);
        g1 = readGraph(g1, rootPath + "testG4.txt");
        assert g1 != null;
        GraphPath gp = new GraphPath(g1, 0);
        assert gp.hasPath(4);
        assert !gp.hasPath(1);
        gp.printPath(8);

        /////////////////////////////// find shortest path
        //      0   1 - 2
        //      |  \     |
        //      3   4   5
        //      |     \
        //      6 - 7 - 8
        ////////////////////////////////
        Graph g2 = new DenseGraph(9, false);
        g2 = readGraph(g2, rootPath + "testG4.txt");
        assert g2 != null;
        GraphShortestPath gsp1 = new GraphShortestPath(g2, 0);
        assert gsp1.hasPath(4);
        assert !gsp1.hasPath(1);
        gsp1.printPath(8);
    }
}
